extends Control

signal click
signal last_clicked
signal next_clicked
signal skip_clicked

# 低耦合RPG对话框，通过赋值text来显示文本

var text setget set_text # 要显示的文本
var role_name setget set_role_name
export(float) var speed = 0.02 # 单个文字显示时间



onready var tw = $"NinePatchRect/RichTextLabel/Tween"
onready var rht = $"NinePatchRect/RichTextLabel"
onready var nameLab = $"NinePatchRect/name/Label"

# ============ 节点虚函数 =============

func _ready():
	rht.bbcode_enabled = true # 开启富文本标签的BBCode模式
	pass

# ============ 自定义函数、方法 =============
# 显示对话框
func show():
	visible = true
	pass

# 隐藏对话框
func hide():
	visible = false

# 按打字机效果显示富文本框text属性中的文本
func show_text():
	var time = rht.text.length() * speed
	rht.percent_visible = 0
	tw.interpolate_property(rht,"percent_visible",0,1,time)
	tw.start()
	
# ============ 属性setget处理函数 =============

# 为元件赋值text属性 - 对话的文字内容
func set_text(value):
	yield(get_tree().create_timer(0.5), "timeout")
	rht.bbcode_text = value
	show_text()
	pass
	
# 为元件赋值role_name属性 - 对话的角色名称
func set_role_name(value):
	nameLab.text = value
	pass

# ============ 事件处理函数 =============

func _on_RichTextLabel_click():
	emit_signal("click")
	pass # Replace with function body.


func _on_lastBtn_pressed():
	emit_signal("last_clicked")
	pass # Replace with function body.


func _on_nextBtn_pressed():
	emit_signal("next_clicked")
	pass # Replace with function body.


func _on_skipBtn_pressed():
	emit_signal("skip_clicked")
	pass # Replace with function body.
